<?php

class AtomController extends Zend_Controller_Action 
{
	public $slug;
	public $data;
	
	public function handleAction()
	{
		$request = $this->getRequest();
		$response = $this->getResponse();
		
		//$response->setHeader("Content-Type", "application/atomserv+xml; charset=utf-8");
		$response->setHeader("Content-Type", "application/xml; charset=utf-8");
		
		switch ($request->getMethod()) {
			case 'GET':
				if ($request->getParam('key') != null) {
					$request->setActionName("view");
					$this->view($request->getParam('key'));
				} else {
					$request->setActionName("collection");
					$this->collection();
				}
			break;
			case 'POST':
				$this->slug = $request->getHeader("slug");
				$this->data = new SimpleXMLElement($request->getRawBody());
				$request->setActionName("create");
				$this->create();
			break;
			case 'PUT':
				$this->data = new SimpleXMLElement($request->getRawBody());
				$request->setActionName("update");
				$this->update($request->getParam('key'));
			break;
			case 'DELETE':
				$request->setActionName("delete");
				$this->delete($request->getParam('key'));
			break;
		}
	}
	
	protected function errorNotFound()
	{
		$this->getResponse()->clearHeaders();
		throw new Zend_Controller_Dispatcher_Exception('404 - Page not found');
	}
	
	public function collection()
	{
		
	}
	
	public function create()
	{
		
	}
	
	public function view($key)
	{
		
	}
	
	public function update($key)
	{
		
	}
	
	public function delete($key)
	{
		
	}

	/**
	 * Return the Request object
	 *
	 * @return Zend_Controller_Request_Http
	 */
	public function getRequest()
	{
		return $this->_request;
	}
	
	/**
	 * Return the Response object
	 *
	 * @return Zend_Controller_Response_Http
	 */
	public function getResponse()
	{
		return $this->_response;
	}
}
